Ext.define('Admin.view.trade.TradeMenuController', {
	        extend : 'Admin.app.BaseController',
	        alias : 'controller.trademenu',

	        onClearData : function() {
		        var me = this, vm = me.getViewModel();
		        var items = me.getView().items.items;
		        Ext.each(items, function(item) {
			                if (item.getStore) {
				                item.getStore().proxy.extraParams = {};
				                item.getStore().removeAll();
			                }
		                });
		        vm.set('tradeRecord', null);
	        },

	        onRecordChange : function(record) {
		        var me = this, vm = me.getViewModel();
		        vm.set('tradeRecord', record);
		        var activeTab = me.getView().getActiveTab();
		        if (activeTab && record) {
			        activeTab.fireEvent('refresh', record);
		        }
	        },

	        onTabChange : function(tabPanel, newCard, oldCard, eOpts) {
		        var me = this, vm = me.getViewModel(), record = vm.get('tradeRecord');
		        record && newCard.fireEvent('refresh', record);
	        },

	        onTradeBidRefresh : function(record) {
		        var me = this, vm = me.getViewModel();
		        var treeRecord = vm.get('record');
		        var store = vm.getStore('tradeBidStore');
		        store.proxy.extraParams = {
			        id : record.data.id,
			        buyer : treeRecord.data.id
		        }
		        store.reload();
	        },

	        onSaveBid : function(btn) {
		        var me = this, vm = me.getViewModel();
		        var store = vm.getStore('tradeBidStore');
		        var modified = store.getModifiedRecords();
		        if (modified.length === 0) {
			        return;
		        }
		        var datas = [];
		        Ext.each(modified, function(record) {
			                data = {
				                id : record.data.id,
				                price : record.data.price,
				                value : record.data.value
			                }
			                datas.push(data);
		                });
		        Admin.Ajax.request({
		        			mask : btn.ownerCt.ownerCt,
			                method : 'PUT',
			                url : 'rest/api/tradebid/saves',
			                params : Ext.encode(datas),
			                fnSuccess : function() {
				                store.commitChanges();
			                }
		                })

	        },

	        onSubmitToMarket : function(btn) {

	        },

	        onBeforEdit : function(editor, context, eOpts) {
		        return true;
	        },

	        onTradeResultRefresh : function(record) {
		        var me = this, vm = me.getViewModel();
		        var store = vm.getStore('tradeResultStore');
		        store.proxy.extraParams = {
			        id : record.data.id
		        }
		        store.reload();
	        },

	        onTradeClearingRefresh : function(btn) {
		        var me = this, vm = me.getViewModel();
		        var trade = vm.get('tradeRecord');
		        var saler = vm.get('record');
		        var store = vm.getStore('tradeClearingStore');
		        store.proxy.extraParams = {
			        id : trade.data.id,
			        buyer : saler.data.id
		        }
		        store.reload();
	        }
        });